a,b = list(map(int, input().split()))

from math import *

ans = 0

len1 = ceil(log(a+1) / log(3))
len2 = ceil(log(b+1) / log(3))

#print(len1)
#print(len2)


if len1 < len2:
  if 3**(len1-1) == a:
    print(a)
  else:
    print(3**len1)
else:
  print(a)
